package com.scvtc.service.research.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scvtc.domain.ResResult;
import com.scvtc.domain.dto.research.intellectual.ResearchIntellectualDto;
import com.scvtc.domain.entity.research.ResearchIntellectual;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.domain.vo.research.intellectual.ResearchIntellectualVo;
import com.scvtc.mapper.research.ResearchIntellectualMapper;
import com.scvtc.service.research.ResearchIntellectualService;
import com.scvtc.utils.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 科研知识产权信息(ResearchIntellectual)表服务实现类
 *
 * @author yiFei
 * @since 2022-06-02 16:17:09
 */
@Service("researchIntellectualService")
public class ResearchIntellectualServiceImpl extends ServiceImpl<ResearchIntellectualMapper, ResearchIntellectual> implements ResearchIntellectualService {
    /**
     * 查询科研知识产权信息
     *
     * @param current
     * @param size
     * @param researchIntellectualVo
     * @return
     */
    @Override
    public ResResult<PageVo<List<ResearchIntellectualVo>>> getAllResearchIntellectual(Long current, Long size, ResearchIntellectualVo researchIntellectualVo) {
        // 分页查询
        Page<ResearchIntellectual> page = getBaseMapper().getAllResearchIntellectual(new Page<ResearchIntellectual>(current, size), researchIntellectualVo);
        // BeanCopy
        List<ResearchIntellectualVo> researchIntellectualVoList = BeanCopyUtils.copyBean(page.getRecords(), ResearchIntellectualVo.class);
        // 返回成功值
        return ResResult.noMsgSuccess(new PageVo<>(researchIntellectualVoList, page.getTotal()));
    }

    /**
     * 添加科研知识产权信息
     *
     * @param researchIntellectualDto
     * @return
     */
    @Override
    public ResResult<?> addResearchIntellectual(ResearchIntellectualDto researchIntellectualDto) {
        // 如果考虑后端安全性需要判断教工号是否存在 (代码可参考学生获奖表)
        // Bean拷贝
        ResearchIntellectual researchIntellectual = BeanCopyUtils.copyBean(researchIntellectualDto, ResearchIntellectual.class).setId(null);
        // 判断是否成功
        if (save(researchIntellectual)) {
            return ResResult.success(researchIntellectual.getId());
        }
        return ResResult.fail();
    }

    /**
     * 修改的单个知识产权信息
     *
     * @param researchIntellectualDto
     * @return
     */
    @Override
    public ResResult<?> updateResearchIntellectual(ResearchIntellectualDto researchIntellectualDto) {
        // 如果考虑后端安全性需要判断教工号是否存在 (代码可参考学生获奖表)
        // Bean拷贝
        ResearchIntellectual researchIntellectual = BeanCopyUtils.copyBean(researchIntellectualDto, ResearchIntellectual.class);
        // 判断是否成功
        if (updateById(researchIntellectual)) {
            return ResResult.success();
        }
        return ResResult.fail();
    }

    /**
     * 删除单个科研知识产权信息
     *
     * @param id
     * @return
     */
    @Override
    public ResResult<?> deleteResearchIntellectual(Long id) {
        // 判断是否成功
        if (removeById(id)) {
            return ResResult.success();
        }
        return ResResult.fail();
    }

    /**
     * 删除多个科研知识产权信息
     *
     * @param ids
     * @return
     */
    @Override
    public ResResult<?> deleteMultipleResearchIntellectual(Long[] ids) {
        // 判断是否成功
        if (removeByIds(Arrays.asList(ids))) {
            return ResResult.success();
        }
        return ResResult.fail();
    }
}

